package ca.shojaei.mini_sat;

import java.util.*;

public class And extends Clause {
	
	private Clause p;
	private Clause q;
	private String symbol = "&";
	
	public And(Clause p, Clause q, String symbol) {
		super();
		this.p = p;
		this.q = q;
		this.symbol = symbol;
		this.unary = false;
	}
	
	public And(){
		super();
		this.unary = false;
		this.evaluable = false;
	}
	
	public Clause getRight(){
		return getQ();
	}
	
	public void setRight( Clause c){
		setQ(c);
	}
	
	public Clause getLeft(){
		return getP();
	}
	
	public void setLeft(Clause c){
		setP(c);
	}
	
	public Clause getP() {
		return p;
	}
	public void setP(Clause p) {
		this.p = p;
	}
	public Clause getQ() {
		return q;
	}
	public void setQ(Clause q) {
		this.q = q;
	}
	public String getSymbol() {
		if(this.negated){
			String str = "!".concat(this.symbol);
			return str;
		}
		return symbol;
	}
	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}
	
	public boolean evaluate(Model m)
	{
		boolean out;
	    out =  p.evaluate(m) && q.evaluate(m);
		if(negated)
			out = !out;
		
		return out;
		
	}
	public Vector<int[]> getDIMACS(Model m)
	{
		Vector<int[]> result = new Vector<int[]>();
		Vector<int[]> pv = p.getDIMACS(m);
		Vector<int[]> qv = q.getDIMACS(m);
		
		for(int i = 0; i < pv.size(); i++)
		{
			result.add(pv.get(i));
		}
		
		for(int i = 0; i < qv.size(); i++)
		{
			result.add(qv.get(i));
		}
		
		return result;
	}

}
